package com.xbfinal.myzhxy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xbfinal.myzhxy.pojo.Teacher;
import com.xbfinal.myzhxy.service.TeacherService;
import com.xbfinal.myzhxy.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

@RestController
@RequestMapping("/sms/teacherController")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;
    @GetMapping("getTeachers/{pageNo}/{pageSize}")
    public Result getClazzsByOpr(
            @PathVariable("pageNo") Integer pageNo,
            @PathVariable("pageSize") Integer pageSize,
            @PathParam(value = "name") String name
            ){
        //分页
        Page<Teacher> page=new Page<>(pageNo,pageSize);
        //然后通过service查询,分页查询根据名字
        IPage<Teacher> iPage
                = teacherService.getBradeByOpr(page,name);
        return  Result.ok(iPage);

    }

    @ApiOperation("添加和修改教师信息")
    @PostMapping("/saveOrUpdateTeacher")
    public Result saveOrUpdateTeacher(
            @RequestBody Teacher teacher
    ){
        //调用service添加
        teacherService.saveOrUpdate(teacher);
        return Result.ok().message("添加成功");
    }
    @ApiOperation("删除一个或者多个教师信息")
    @DeleteMapping("/deleteTeacher")
    public Result deleteTeacher(
            @RequestBody List<Integer> ids
    ){
        teacherService.removeByIds(ids);
        return Result.ok();
    }
}
